package com.ncloud.resman.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.ncloud.resman.entity.SwitchVlan;
import com.ncloud.resman.mapper.SequenceMapper;
import com.ncloud.resman.mapper.SwitchSubAssignMapper;
import com.ncloud.resman.mapper.SwitchVlanMapper;
import com.ncloud.resman.service.SwitchVlanService;
@Service
public class SwitchVlanServiceImpl implements SwitchVlanService{
	@Resource
	private SwitchVlanMapper switchVlanMapper;
	@Resource
	private SwitchSubAssignMapper switchSubAssignMapper;
	@Resource
	private SequenceMapper sequenceMapper;

	@Override
	public JSONObject getSwitchVlanInfo(JSONObject json) {
		long deviceId = json.getLongValue("deviceId");
		JSONObject result = new JSONObject();
		List<JSONObject> switchBase = switchSubAssignMapper.getSwitchBaseInfo(deviceId);
		if(switchBase!=null && switchBase.size()>0){
			result.put("switchBase", switchBase.get(0));
		}
		List<JSONObject> vlans = switchVlanMapper.getSwitchVlanInfo(deviceId);
		if(vlans!=null && vlans.size()>0){
			result.put("vlans", vlans);
		}
		return result;
	}

	@Override
	public int insertSwitchVlan(SwitchVlan switchVlan) {
		Long vlanId = sequenceMapper.getSequence("vlan_id").longValue();
		switchVlan.setVlanId(vlanId);
		return switchVlanMapper.insertSwitchVlan(switchVlan);
	}

	@Override
	public int updateSwitchVlan(SwitchVlan switchVlan) {
		return switchVlanMapper.updateSwitchVlan(switchVlan);
	}

	@Override
	public int deleteSwitchVlan(Long vlanId) {
		return switchVlanMapper.deleteSwitchVlan(vlanId);
	}
}
